<template>
  <el-card>
    <el-row>
      <span class="section-title">基础信息</span>
    </el-row>

    <el-row :gutter="20" class="mt15">
      <el-col :span="8">
        <span>企业名称：</span>
        <span>{{ state.data.orgName }}</span>
      </el-col>
      <el-col :span="8">
        <span>落地类型：</span>
        <span>{{ getLabelByValue(implTypeOptions, state.data.implTypeId) }}</span>
      </el-col>
      <el-col :span="8">
        <span>入驻类型：</span>
        <span>{{ getLabelByValue(entryTypeOptions, state.data.entryTypeId) }}</span>
      </el-col>
    </el-row>

    <el-row :gutter="20" class="mt15">
      <el-col :span="24">
        <span>注册地址：</span>
        <span>{{ state.data.regAddress }}</span>
      </el-col>
    </el-row>

    <el-row :gutter="20">
      <el-col :span="8" class="mt15">
        <span>联系人：</span>
        <span>{{ state.data.linkMan }}</span>
      </el-col>
      <el-col :span="8" class="mt15">
        <span>电话：</span>
        <span>{{ state.data.linkPhone }}</span>
      </el-col>
      <el-col :span="8" class="mt15">
        <span>企业性质：</span>
        <span>{{ getLabelByValue(entNatureOptions, state.data.entNatureId) }}</span>
      </el-col>
      <el-col :span="8" class="mt15" v-if="state.data.entNatureId == '3'">
        <span>企业性质（其他）：</span>
        <span>{{ state.data.entNatureOther }}</span>
      </el-col>
      <el-col :span="8" class="mt15">
        <span>企业类型：</span>
        <span>{{ getLabelByValue(enterpriseTypeOptions, state.data.enterpriseType) }}</span>
        <!--        <el-radio-group v-model="state.data.enterpriseType" class="ml20">-->
        <!--          <el-radio v-for="(item,index) in enterpriseTypeOptions"-->
        <!--                    :key="index"-->
        <!--                    size="small"-->
        <!--                    :value="item.value"-->
        <!--                    :label="item.label"/>-->
        <!--        </el-radio-group>-->
      </el-col>
      <el-col :span="8" class="mt15" v-if="state.data.enterpriseType == '3'">
        <span>分支机构：</span>
        <span>{{ state.data.entNatureBranch }}</span>
      </el-col>
      <el-col :span="8" class="mt15" v-if="state.data.enterpriseType == '4'">
        <span>企业类型（其他）：</span>
        <span>{{ state.data.enterpriseTypeOther }}</span>
      </el-col>
      <el-col :span="8" class="mt15">
        <span>注册资金：</span>
        <span>{{ state.data.regCapital }}</span>
      </el-col>
      <el-col :span="8" class="mt15">
        <span>行业类别：</span>
        <span>{{ getLabelByValue(industryMTypeOptions, state.data.industryMtypeId) }}</span>
      </el-col>
      <el-col :span="8" class="mt15" v-if="state.data.industryMtypeId == '5'">
        <span>行业类别（其他）：</span>
        <span>{{ state.data.industryMtypeOther }}</span>
      </el-col>
      <el-col :span="8" class="mt15">
        <span>主营业务：</span>
        <span>{{ state.data.bizScope }}</span>
      </el-col>
      <el-col :span="8" class="mt15">
        <span>纳税人类别：</span>
        <span>{{ getLabelByValue(taxpayerTypeOptions, state.data.taxpayerType) }}</span>
      </el-col>
    </el-row>

    <el-row :gutter="20" class="mt15">
      <el-col :span="24">
        <span>企业简介及入驻原因：</span>
        <span>{{ state.data.introduction }}</span>
      </el-col>
    </el-row>

    <el-row class="mt20">
      <span class="section-title">附件信息</span>
    </el-row>

    <el-row v-for="(item,index) in state.fileList" class="mt10">
      <el-col :span="8">{{ item.fileName + '：' }}</el-col>
      <el-col :span="16">
        <DownLoad v-model="item.fileId"/>
      </el-col>
    </el-row>
  </el-card>
</template>

<script lang="ts" setup>
import {getCurrentInstance, onBeforeMount, onMounted, reactive, watch} from "vue";
import {queryEntEntity} from "/@/api/entEntry/entBaseInfo";
import DownLoad from "/@/views/common/downLoad.vue";
import {selectFileList} from "/@/views/enterpriseManager/dictionary/dictionary"

import {
  getLabelByValue,
  implTypeOptions,
  entryTypeOptions,
  entNatureOptions,
  enterpriseTypeOptions, industryMTypeOptions, taxpayerTypeOptions
} from "../dictionary/constant";
import {getEntApplyFileList} from "/@/api/entEntry/entApplyFile";
import {queryEntApplyEntityByEntId} from "/@/api/entEntry/entApply";

const {proxy} = getCurrentInstance() as any;

const props = defineProps<{
  entId: string;
  applyId: string;
}>();

const state = reactive({
  da: '1',
  data: {
    orgName: "",
    implTypeId: "",
    entryTypeId: "",
    enterpriseType: "1",
    industryMtypeId: "",
    enterpriseTypeOther: "",
    entNatureOther: "",
    industryMtypeOther: "",
    entNatureBranch: "",
    regAddress: "",
    linkMan: "",
    linkPhone: "",
    entNatureId: "",
    regCapital: "",
    taxpayerType: "",
    introduction: "",
    fileId: "",
  },
  fileList: [],
  loading: false
});

const init = async () => {
  try {
    if (!props.entId) return;
    const res = await queryEntEntity(props.entId);
    if (!res || !res.data) {
      proxy.$wigem.alert.warning("企业信息不存在！");
      return;
    }
    state.data = res.data;

    //根据企业id查询入驻信息，再根据applyId查询附件
    const applyRes = await queryEntApplyEntityByEntId(props.entId);
    if (!applyRes || !applyRes.data) {
      proxy.$wigem.alert.warning("企业入驻信息不存在！");
      return;
    }

    //查询附件
    const entApplyFileRes = await getEntApplyFileList({applyId: applyRes.data.id})

    if (!entApplyFileRes.success || entApplyFileRes.data.length <= 0) {
      return;
    }

    let applyType = ""
    for (const item of entApplyFileRes.data) {
      if (item.applyType) {
        applyType = item.applyType;
        break;
      }
    }
    //加载附件模版
    const fileListTemp = selectFileList(applyType);

    if (!fileListTemp || fileListTemp.length <= 0) {
      proxy.$wigem.alert.warning("附件模版不存在！");
      return;
    }

    entApplyFileRes.data.forEach((item) => {
      fileListTemp.forEach((listItem) => {
        if (listItem.fileNo == item.fileNo) {
          listItem.fileId = item.fileId;
          item["fileName"] = listItem.fileName;
        }
      });
    });
    state.fileList = entApplyFileRes.data;
  } catch (error) {
    proxy.$wigem.alert.error("查询企业信息失败！");
  }
};
onBeforeMount(() => {
  // 初始化时调用
  init();
});

watch(
    () => props.entId,
    () => {
      init();
    }
);
</script>

<style scoped>
.section-title {
  font-size: 18px;
  font-weight: bold;
}

.mt20 {
  margin-top: 20px;
}
</style>
